#include <sound_play/sound_play.h>
#include <unistd.h>
#include <iostream>
#include <string>

using namespace std;

void sleepok(int t, ros::NodeHandle &nh)
{
  if (nh.ok())
		sleep(t);
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "sound_play_test");

  ros::NodeHandle nh;
  sound_play::SoundClient sc;

  sleepok(1, nh);

  cout << "----------- UNICEBOT TALKER -----------";
  
  while(1)
  {
	string mystr;
	cout << "\n\nWhat do you want to say ? (quit for exit)\n\t1 : Presentation \n\t2 : R2D2 SOS \n\tOther : write your message and press enter\n";
	getline (cin, mystr);

	if(mystr.compare("1")==0)
	{
		string s = "Hello ! My name is Turtlebot ! Welcome at the university of Nice.";
		cout << "\nTalking...";		
		sc.say(s);		
		sleepok(6, nh);
		cout << "\nSaid : " << s;
	}
	else if(mystr.compare("2")==0)
	{
		cout << "\nTalking...";	
		sc.playWave("/home/turtlebot/Musique/r2d2.wav");		
		sleepok(3, nh);
	}
	else if(mystr.compare("3")==0)
	{
		//sc.playWave("/usr/share/xemacs21/xemacs-packages/etc/sounds/boing.wav");
	}
	else if(mystr.compare("quit")==0)
	{
		exit(0);
	}
	else
	{
		cout << "\nTalking...";	
		sc.say(mystr);		
		sleepok((mystr.size()/4), nh);
		cout << "\nSaid : " << mystr;
	}
  }
}
